package com.example.springLearning.part5.entity;

import lombok.Data;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
@Data
public class Student {

    private String name;
    private int age;
    private String sex;

//    private Student() {}



    public Student(String name, int age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public static class Builder {
        private String name;
        private int age;
        private String sex;
        public Builder() {}
        private Builder setName(String name) {
            this.name = name;
            return this;
        }

        private Builder setAge(int age) {
            this.age = age;
            return this;
        }

        private Builder setSex(String sex) {
            this.sex = sex;
            return this;
        }

        public Student build() {
            return new Student(name, age, sex);
        }

    }

    private Student build() {
        return this;
    }

    @Bean
    public Student studentabc() {
        Student student = createStudent("ssh", 25, "man");
        return student;
    }

    @Bean
    public Student student1() {
        return createStudent("ssh1");
    }

    public Student createStudent(String name) {
        return createStudent(name, 0, "");
    }

    public Student createStudent(String name, int age, String sex) {
        return Student.newBuilder().setName(name).setAge(age).setSex(sex).build();
    }


}
